package com.taoism.base;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableAsync;

import java.text.SimpleDateFormat;
import java.util.TimeZone;

/**
 * 基础启动应用程序
 *
 * @author 李嘉
 * @version 1.0
 * @Description 基础启动应用程序
 * @date 2019-05-27 16:36
 */
@EnableAsync
@SpringBootApplication(scanBasePackages = {"com.taoism.*"})
@PropertySource(value = {"file:config/application.yml", "file:config/application-dev.yml", "file:config/application-test.yml", "file:config/application-pro.yml", "file:config/application-prod.yml", "file:config/application-common.yml"}, ignoreResourceNotFound = true, encoding = "UTF-8")
public abstract class BaseApplication {

    /**
     * 序列化问题解决
     *
     * @return
     */
    @Bean
    public ObjectMapper objectMapper() {
        return (new ObjectMapper()).configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
                .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
                .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
                .setTimeZone(TimeZone.getTimeZone("GMT+8"))
                .setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    }
}
